using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class OccurrenceCodeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public OccurrenceCodeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v231] = HL7TableType.User;
						tableVersionTypes[HL7Version.v24] = HL7TableType.User;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v231] = new string[]{"01","02","03","04","05","06","09","10","11","12","17","18","19","20","21","22","24","25","26","27","28","29","30","31","32","33","34","35","36","37","40","41","42","43","44","45","46","47 ... 49","50","51","70 ... 99","A1","A2","A3"};
						validVersionCodes[HL7Version.v24] = new string[]{"01","02","03","04","05","06","09","10","11","12","17","18","19","20","21","22","24","25","26","27","28","29","30","31","32","33","34","35","36","37","40","41","42","43","44","45","46","47 ... 49","50","51","70 ... 99","A1","A2","A3"};
						validVersionCodes[HL7Version.v25] = new string[]{""};
						validVersionCodes[HL7Version.v251] = new string[]{"..."};
						validVersionCodes[HL7Version.v26] = new string[]{"..."};
						validVersionCodes[HL7Version.v27] = new string[]{"…"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v231] = new string[]{"Auto accident","No fault insurance involved-including auto accident/other","Accident/tort liability","Accident/employment related","Other accident","Crime victim","Start of infertility treatment cycle","Last menstrual period","Onset of symptoms/illness","Date of onset for a chronically dependent individual","Date outpatient occupational therapy plan established or last reviewed","Date of retirement patient/beneficiary","Date of retirement spouse","Guarantee of payment began","UR notice received","Date active care ended","Date insurance denied","Date benefits terminated by primary payor","Date SNF bed available","Date home health plan established","Spouse’s date of birth","Date outpatient physical therapy plan established or last reviewed","Date outpatient speech pathology plan established or last reviewed","Date beneficiary notified of intent to bill (accommodations)","Date beneficiary notified of intent to bill (procedures or treatments)","First day of the Medicare coordination period for ESRD beneficiaries covered by EGHP","Date of election of extended care facilities","Date treatment started for P.T.","Date of inpatient hospital discharge for covered transplant patients","Date of inpatient hospital discharge for non-covered transplant patient","Scheduled date of admission","Date of first test for pre-admission testing","Date of discharge","Scheduled date of canceled surgery","Date treatment started for O.T.","Date treatment started for S.T.","Date treatment started for cardiac rehab.","Payer codes","Date lien released","Date treatment started for psychiatric care","Occurrence span codes and dates","Birthdate - insured A","Effective date - insured A policy","Benefits exhausted payer A"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Auto accident","No fault insurance involved-including auto accident/other","Accident/tort liability","Accident/employment related","Other accident","Crime victim","Start of infertility treatment cycle","Last menstrual period","Onset of symptoms/illness","Date of onset for a chronically dependent individual","Date outpatient occupational therapy plan established or last reviewed","Date of retirement patient/beneficiary","Date of retirement spouse","Guarantee of payment began","UR notice received","Date active care ended","Date insurance denied","Date benefits terminated by primary payor","Date SNF bed available","Date home health plan established","Spouse's date of birth","Date outpatient physical therapy plan established or last reviewed","Date outpatient speech pathology plan established or last reviewed","Date beneficiary notified of intent to bill (accommodations)","Date beneficiary notified of intent to bill (procedures or treatments)","First day of the Medicare coordination period for ESRD beneficiaries covered by EGHP","Date of election of extended care facilities","Date treatment started for P.T.","Date of inpatient hospital discharge for covered transplant patients","Date of inpatient hospital discharge for non-covered transplant patient","Scheduled date of admission","Date of first test for pre-admission testing","Date of discharge","Scheduled date of canceled surgery","Date treatment started for O.T.","Date treatment started for S.T.","Date treatment started for cardiac rehab.","Payer codes","Date lien released","Date treatment started for psychiatric care","Occurrence span codes and dates","Birthdate - insured A","Effective date - insured A policy","Benefits exhausted payer A"};
						validVersionDescriptions[HL7Version.v25] = new string[]{""};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Use NUBC codes"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Use NUBC codes"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Use NUBC codes"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
